package com.xiaoyg.algorithm.two_pointer;

public class LongestPalindrome {
    public int longestPalindrome(String s) {
        String res = "";
        int len = s.length();
        for (int i = 0; i < len; ++i)
        {
            String s1 = palindrome(s, i, i);
            String s2 = palindrome(s, i, i + 1);
            res = s1.length() > res.length() ? s1 : res;
            res = s2.length() > res.length() ? s2 : res;
        }
        return res.length();
    }

    public String palindrome(String s, int l,int r){
        char [] charArray =  s.toCharArray();
        while (l >= 0 && r < s.length() && charArray[l] == charArray[r]){
            --r;
            ++l;
        }
        return s.substring(l+1, r - l -1);
    }
}
